<?php
namespace data\site;
use \data\BaseData;
/**
 * 站点主商户管理
 */
class SiteMainData extends BaseData{
    
    
    /**
     * 读取一个信息
     */
    public function find($param){
        $fields = ['id','name'=>'like'];
        $where = $this->parseWhere($fields,$param);
        if( !$where )  dataE('查询条件不能为空');
        $info  = M('site_main')->where($where)->find();
        return $info;
    }
    
    /**
     * 添加一个信息
     */
    public function add($data){        
        $check = [                    
            'opentype'      => ['reg'=>[1,2,3,4]],
            'adduserid'     => ['reg'=>'int'], 
            'level'         => ['def'=>1,'reg'=>'int'],
            'name'          => '',
            'addtime'       => ['val'=> SYS_TIME],
            'edittime'      => ['val'=> 0],
        ];
        $save = $this->verifyData($check,$data);
        return M('site_main')->insertGetId($save);
    }
    
    
    /**
     * 编辑一个信息
     */
    public function edit($id,$data){        
        $check = [                    
            'opentype'      => ['reg'=>[1,2,3,4]],
            'adduserid'     => ['reg'=>'int'], 
            'level'         => ['reg'=>'int'],
            'name'          => '',
            'edittime'      => ['val'=> SYS_TIME],
        ];
        $save = $this->verifyData($check,$data);
        if( !$save ) return false;
        $where = ['id'=>$id];
        $result = M('site_main')->where($where)->update($save);
        if($result === false ) dataE('修改站点信息失败');
        return $result;
    }
    
    
}